﻿package mortal.game.scene3D.ai.ais
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import frEngine.event.*;
    import mortal.component.gLinkText.*;
    import mortal.component.gconst.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.control.subControl.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.rules.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.ai.base.*;
    import mortal.game.scene3D.ai.data.*;
    import mortal.game.scene3D.ai.singleAIs.autofight.*;
    import mortal.game.scene3D.events.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.AstarAnyDirection.data.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.scene3D.util.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.copy.petBreak.*;
    import mortal.game.view.guide.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.task.data.*;
    import mortal.mvc.core.*;

    public class AutoFightAI extends AICommand
    {
        private var _isTonadoing:Boolean = false;
        private var _isPickupEndtoTask:Boolean = false;
        private var _pickupEndtoTaskTime:int = -1;
        private var _tonadoMovedList:Array;
        private var _rollingTime:int = -1;
        protected var _isCancelAll:Boolean = false;
        protected var _aiList:Array;
        protected var _curAI:IAICommand;
        private var _timer:FrameTimer;
        private var _curFrame:int = 0;
        private var _comboTime:int = 0;
        private var _pickUpItemAI:AutoFightPickUpItemAI;
        private var _pickUpTimer:Timer;
        private var _strategy:IAutofightStrategy;
        private var _flame:IFlashFrame;
        private var _resumeToTaskGroup:int = -1;
        private var _keyboadUseSkill:SkillInfo;
        public static var _instance:AutoFightAI;
        public static var isWorking:Boolean = false;
        public static var isLeading:Boolean = false;
        public static var isMoveToPickupItem:Boolean = false;

        public function AutoFightAI()
        {
            this._tonadoMovedList = [];
            this._aiList = [];
            this._pickUpItemAI = new AutoFightPickUpItemAI();
            this._pickUpTimer = new Timer(2300);
            this._pickUpTimer.addEventListener(TimerEvent.TIMER, this.stopPickUpAi);
            return;
        }// end function

        public function get curAI() : IAICommand
        {
            return this._curAI;
        }// end function

        public function set curAI(param1:IAICommand) : void
        {
            this._curAI = param1;
            return;
        }// end function

        public function get isInAroundFight() : Boolean
        {
            if (AutoFightBossSelectAI.instance.range < 0)
            {
                return false;
            }
            return true;
        }// end function

        override public function start(param1:Function = null) : void
        {
            this.cancelAll();
            this._flame = FrameManager.flashFrame;
            isWorking = true;
            this._isTonadoing = false;
            this._tonadoMovedList = null;
            isMoveToPickupItem = false;
            this._isPickupEndtoTask = false;
            this._pickupEndtoTaskTime = -1;
            this._curFrame = 0;
            this.sceneUpdateHandler();
            super.start(param1);
            AutoFightBossSelectAI.instance.sourcePoint.x = PetBreakCopyUtil.player.x2d;
            AutoFightBossSelectAI.instance.sourcePoint.y = PetBreakCopyUtil.player.y2d;
            AutoFightBossSelectAI.instance.range = _data.range;
            AutoFightBossSelectAI.instance.onlyIds = data.params as Dictionary;
            this._timer = new FrameTimer(2);
            this._timer.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            this._timer.start();
            if (this._pickUpTimer.running)
            {
                this._pickUpTimer.stop();
            }
            this._pickUpItemAI.start();
            GuideEffect.showAutoFightStatus(true);
            if (data.times > 0)
            {
                NetDispatcher.addCmdListener(ServerCommand.TaskUpdate, this.taskUpdateHandler);
            }
            Dispatcher.addEventListener(EventName.CDPublicCDEnd, this.onEnterFrameHandler);
            Dispatcher.addEventListener(EventName.Scene_Update, this.sceneUpdateHandler);
            Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFightAIStatusChange, true));
            Dispatcher.addEventListener(EventName.Scene_RemoveEntity, this.bossKilledHandler);
            FrEventDispatcher.instance.proxyAddEventListener(PetBreakCopyUtil.player, PlayerEvent.PLAYER_ACTION_CHANGE, this.roleStatusChanged);
            this.startAIList();
            return;
        }// end function

        private function bossKilledHandler(param1 = null) : void
        {
            if (CopyUtil.isInCopy && this._strategy is AutofightStrategyCopyBase)
            {
                Cache.instance.autoFight.updateBossKilled();
            }
            return;
        }// end function

        public function pickupEndToTask(param1:int) : void
        {
            this._resumeToTaskGroup = param1;
            this._isPickupEndtoTask = true;
            AutoFightPickUpItemAI.hasDrop = true;
            this._pickupEndtoTaskTime = this._flame.getTime();
            return;
        }// end function

        public function get isWaittingForPickupEnd() : Boolean
        {
            if (this._isPickupEndtoTask)
            {
                if (this._flame.getTime() - this._pickupEndtoTaskTime < 600)
                {
                    return true;
                }
            }
            return false;
        }// end function

        private function roleStatusChanged(param1:Object = null) : void
        {
            if (PetBreakCopyUtil.player.actionName == ActionName.Tornado)
            {
                this._isTonadoing = true;
                this.onEnterFrameHandler();
            }
            else if (this._isTonadoing)
            {
                if (this.isWalking)
                {
                    this.cancelAll();
                }
                this._tonadoMovedList = null;
                this._isTonadoing = false;
            }
            return;
        }// end function

        private function sceneUpdateHandler(param1 = null) : void
        {
            this._strategy = this.getStrategy();
            this._strategy.setParams(this);
            Cache.instance.autoFight.resetToNearestBossPoint();
            return;
        }// end function

        private function taskUpdateHandler(param1:Object) : void
        {
            var _loc_4:SPlayerTaskUpdate = null;
            var _loc_5:TaskInfo = null;
            var _loc_6:Array = null;
            var _loc_7:GLinkTextData = null;
            var _loc_2:* = param1 as Array;
            if (_loc_2 == null || _loc_2.length == 0)
            {
                return;
            }
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = _loc_2[_loc_3] as SPlayerTaskUpdate;
                _loc_5 = Cache.instance.task.getTaskByCode(_loc_4.taskCode);
                if (AutoFightBossSelectAI.instance.onlyIds != null)
                {
                    _loc_6 = Cache.instance.task.getCurLinkTextDatas(_loc_5);
                    if (_loc_6 != null)
                    {
                        for each (_loc_7 in _loc_6)
                        {
                            
                            if (_loc_7.type == GLinkTextData.boss)
                            {
                                if (_loc_7.totalNum == _loc_7.curNum)
                                {
                                    delete AutoFightBossSelectAI.instance.onlyIds[_loc_7.value1];
                                }
                            }
                        }
                    }
                }
                if (_loc_5 == null || _loc_5.stask == null)
                {
                }
                else if (_loc_5.stask.code != data.times)
                {
                }
                else if (_loc_5.curStep == _loc_5.lastStep)
                {
                }
                else
                {
                    return;
                }
                _loc_3++;
            }
            return;
        }// end function

        override public function stop(param1:Boolean = true) : void
        {
            GuideEffect.showAutoFightStatus(false);
            if (!this._pickUpTimer.running)
            {
                this._pickUpTimer.start();
            }
            isWorking = false;
            this._isTonadoing = false;
            isMoveToPickupItem = false;
            this._isPickupEndtoTask = false;
            this._pickupEndtoTaskTime = -1;
            this._tonadoMovedList = null;
            this._curFrame = 0;
            super.stop();
            this.cancelAll();
            this._timer.stop();
            Dispatcher.removeEventListener(EventName.CDPublicCDEnd, this.onEnterFrameHandler);
            Dispatcher.removeEventListener(EventName.Scene_Update, this.sceneUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.TaskUpdate, this.taskUpdateHandler);
            Dispatcher.removeEventListener(EventName.Scene_RemoveEntity, this.bossKilledHandler);
            Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFightAIStatusChange, false));
            FrEventDispatcher.instance.proxyRemoveEventListener(PetBreakCopyUtil.player, PlayerEvent.PLAYER_ACTION_CHANGE, this.roleStatusChanged);
            return;
        }// end function

        public function setPlayerRolling() : void
        {
            this.cancelAll();
            this._rollingTime = this._flame.getTime();
            return;
        }// end function

        public function get isRolling() : Boolean
        {
            if (this._flame.getTime() - this._rollingTime > 1000)
            {
                return false;
            }
            return true;
        }// end function

        public function cancelAll() : void
        {
            if (this._curAI != null)
            {
                this._isCancelAll = true;
                AIFactory.instance.inAIData(this._curAI.data);
                this._curAI.stop();
                this._curAI = null;
                this._isCancelAll = false;
            }
            this.inPoolAllTobeStartAi();
            isMoveToPickupItem = false;
            return;
        }// end function

        public function startAIList() : void
        {
            if (this._isCancelAll)
            {
                return;
            }
            if (!isWorking)
            {
                return;
            }
            if (this._curAI != null)
            {
                AIFactory.instance.inAIData(this._curAI.data);
                this._curAI = null;
            }
            if (this._aiList.length == 0)
            {
                return;
            }
            this._curAI = this._aiList.shift();
            this._curAI.start(this.startAIList);
            return;
        }// end function

        public function getCurFightingTarget() : Object
        {
            var _loc_1:IAICommand = null;
            if (_loc_1 != null && (_loc_1 is FollowFightAI || _loc_1 is CollectAI))
            {
                return _loc_1.data.target;
            }
            if (this._aiList != null && this._aiList.length > 0)
            {
                _loc_1 = this._aiList[(this._aiList.length - 1)];
                if (_loc_1 != null && (_loc_1 is FollowFightAI || _loc_1 is CollectAI))
                {
                    return _loc_1.data.target;
                }
            }
            return null;
        }// end function

        public function get isPassingNewMap() : Boolean
        {
            var _loc_1:IAICommand = null;
            if (!isWorking)
            {
                return false;
            }
            if (this._curAI == null)
            {
                return false;
            }
            if (this._curAI is PassAI || this._curAI is DelayAI)
            {
                return true;
            }
            if (this._aiList.length > 0)
            {
                _loc_1 = this._aiList[(this._aiList.length - 1)] as IAICommand;
                if (_loc_1 is PassAI || this._curAI is DelayAI)
                {
                    return true;
                }
            }
            return false;
        }// end function

        private function stopPickUpAi(event:TimerEvent) : void
        {
            if (this._pickUpItemAI != null)
            {
                this._pickUpItemAI.stop();
            }
            this._pickUpTimer.stop();
            return;
        }// end function

        public function get isJumping() : Boolean
        {
            if (this._curAI != null && this._curAI is JumpAI)
            {
                return true;
            }
            if (PetBreakCopyUtil.player.isJumping)
            {
                return true;
            }
            return false;
        }// end function

        public function get isFighting() : Boolean
        {
            if (!isWorking)
            {
                return false;
            }
            if (this._curAI == null)
            {
                return false;
            }
            if (this._curAI is CollectAI || this._curAI is FollowFightAI)
            {
                return true;
            }
            return false;
        }// end function

        public function stopCurCollect() : void
        {
            if (this._curAI == null || !(this._curAI is CollectAI))
            {
                return;
            }
            var _loc_1:* = this._curAI;
            this._curAI = null;
            _loc_1.stop();
            return;
        }// end function

        public function get isWalking() : Boolean
        {
            var _loc_1:IAICommand = null;
            if (this._curAI == null)
            {
                return false;
            }
            if (this._aiList.length > 0)
            {
                _loc_1 = this._aiList[(this._aiList.length - 1)] as IAICommand;
                if (_loc_1 is CollectAI || _loc_1 is FollowFightAI)
                {
                    return false;
                }
            }
            if (this._curAI is FollowFightAI)
            {
                return false;
            }
            if (this._curAI is MoveByPathAI || this._curAI is JumpAI || this._curAI is PassAI || DelayAI is DelayAI)
            {
                return true;
            }
            return false;
        }// end function

        public function inPoolAllTobeStartAi() : void
        {
            var _loc_2:IAICommand = null;
            if (this._aiList.length == 0)
            {
                return;
            }
            var _loc_1:int = 0;
            while (_loc_1 < this._aiList.length)
            {
                
                _loc_2 = this._aiList[_loc_1];
                AIFactory.instance.inAIData(_loc_2.data);
                _loc_1++;
            }
            this._aiList = [];
            return;
        }// end function

        public function useSkill(param1:SkillInfo, param2:Boolean = false) : void
        {
            var _loc_4:MonsterPlayer = null;
            this._keyboadUseSkill = param1;
            var _loc_3:* = Cache.instance.cd.getCDData(this._keyboadUseSkill, CDDataType.skillInfo);
            if (_loc_3 != null && _loc_3.isCoolDown && _loc_3.leftTime > 800)
            {
                this._keyboadUseSkill = null;
                return;
            }
            this.onEnterFrameHandler(null);
            if (param1.tSkill.skillId == GameConst.SkillMount)
            {
                GameManager.instance.popupModuleType(ModuleType.DownUpMounts);
                return;
            }
            if (param1.tSkill.skillId == GameConst.SkillThing)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AskSingleZazen));
                return;
            }
            if (param1.tSkill.skillId == GameConst.JPSkillId)
            {
                if (!BuffUtil.isCanRoleWalk())
                {
                    return;
                }
                GameManager.instance.popupModuleType(ModuleType.RUN);
                return;
            }
            if (param1.tSkill.skillId == GameConst.RollingSkillId)
            {
                if (!BuffUtil.isCanRoleWalk())
                {
                    return;
                }
                GameManager.instance.popupModuleType(ModuleType.SPACE);
                return;
            }
            if (param2)
            {
                _loc_4 = AutoFightBossSelectAI.instance.getEntity() as MonsterPlayer;
                if (_loc_4 != null && _loc_4.entityInfo != null && _loc_4.entityInfo.entityInfo != null)
                {
                    GameController.guide.guideUseXp(false);
                    GameProxy.sceneProxy.fight([_loc_4.entityInfo.entityInfo.entityId], param1.skillId, null);
                }
            }
            return;
        }// end function

        private function onEnterFrameHandler(param1 = null) : void
        {
            var _loc_4:ICDData = null;
            var _loc_5:String = this;
            var _loc_6:* = this._curFrame + 1;
            _loc_5._curFrame = _loc_6;
            if (this._curFrame % 100 == 1)
            {
                AutoFightBossSelectAI.instance.updateTaskBossCodes();
            }
            if (this.isWaittingForPickupEnd)
            {
                return;
            }
            if (this._isTonadoing)
            {
                this.MoveToTonadoTarget();
                return;
            }
            if (!BuffUtil.isCanRoleWalk() || this.isJumping)
            {
                return;
            }
            if (this._curAI != null && !this.isWalking)
            {
                return;
            }
            if (PetBreakCopyUtil.player.entityInfo == null || PetBreakCopyUtil.player.entityInfo.isDead || this.isRolling)
            {
                return;
            }
            if (AutoFightPickUpItemAI.hasDrop || isMoveToPickupItem)
            {
                if (this._curAI != null && this._curAI is FollowFightAI)
                {
                    this.cancelAll();
                }
                return;
            }
            if (this._isPickupEndtoTask)
            {
                if (this._resumeToTaskGroup != ETaskGroup._ETaskGroupGuild || Cache.instance.guild.isInGuild)
                {
                    AIManager.cancelAll();
                    GameController.guide.resumeToTask(this._resumeToTaskGroup);
                }
            }
            var _loc_2:* = this._keyboadUseSkill;
            var _loc_3:Boolean = false;
            if (_loc_2 == null)
            {
                _loc_2 = this.skillInfo;
            }
            else
            {
                _loc_4 = Cache.instance.cd.getCDData(this._keyboadUseSkill, CDDataType.skillInfo);
                if (_loc_4 != null && _loc_4.isCoolDown)
                {
                    _loc_2 = this.skillInfo;
                }
                else
                {
                    if (!BuffUtil.isCanRoleFireSkill(this._keyboadUseSkill))
                    {
                        return;
                    }
                    _loc_3 = true;
                }
            }
            if (_loc_2 != null)
            {
                if (_loc_2.isComboSkill)
                {
                    var _loc_5:String = this;
                    var _loc_6:* = this._comboTime + 1;
                    _loc_5._comboTime = _loc_6;
                    if (this._comboTime >= 3)
                    {
                        this._comboTime = 0;
                    }
                }
                if (RolePlayer.instance.isInSpasticity)
                {
                    return;
                }
                if (this.addNextTarget(_loc_2))
                {
                    this._strategy.updateMinDisToCurBossPoint();
                    if (_loc_3)
                    {
                        this._keyboadUseSkill = null;
                    }
                    return;
                }
            }
            else
            {
                return;
            }
            if (!this.isWalking && this._curFrame >= 8)
            {
                this._strategy.chooseMovePath();
            }
            return;
        }// end function

        protected function get skillInfo() : SkillInfo
        {
            return Cache.instance.autoFight.getCanUseSkill(this._comboTime > 0 && this._comboTime < 3);
        }// end function

        private function MoveToTonadoTarget() : void
        {
            var _loc_2:int = 0;
            if (this.isWalking)
            {
                return;
            }
            if (this._tonadoMovedList == null)
            {
                this._tonadoMovedList = [];
                if (ThingUtil.selectEntity != null)
                {
                    this._tonadoMovedList.push(ThingUtil.selectEntity);
                }
            }
            var _loc_1:* = AutoFightBossSelectAI.instance.getEntity(false, this._tonadoMovedList);
            if (_loc_1 == null || _loc_1.entityInfo == null)
            {
                return;
            }
            if (this._tonadoMovedList.length > 1)
            {
                _loc_2 = this._tonadoMovedList.indexOf(_loc_1);
                if (_loc_2 >= 0)
                {
                    this._tonadoMovedList.splice(_loc_2, 1);
                }
            }
            this._tonadoMovedList.push(_loc_1);
            this.cancelAll();
            this.addMoveTo(new Point(_loc_1.x2d, _loc_1.y2d), _loc_1.entityInfo.bodySize);
            this.startAIList();
            return;
        }// end function

        private function getStrategy() : IAutofightStrategy
        {
            if (GameMapUtil.curMapState.isTowerMap)
            {
                return AutofightStrategy_CopyTower.instance;
            }
            if (CopyUtil.isInDefenseCopy || CopyUtil.isInZZXYBattleCopy || CopyUtil.isInGroupDefenseCopy)
            {
                return AutofightStrategy_CopyDefence.instance;
            }
            if (GameMapUtil.curMapState.isJLMDCopy)
            {
                return AutofightStrategy_CopyJLMD.instance;
            }
            if (CopyUtil.isInSixBossCopy)
            {
                return AutofightStrategy_SixBoss.instance;
            }
            if (CopyUtil.isInCopy && !Cache.instance.guild.isInGuild)
            {
                return AutofightStrategyCopyBase.instance;
            }
            return AutofightStrategyBase.instance;
        }// end function

        private function addNextTarget(param1:SkillInfo) : Boolean
        {
            var _loc_3:FollowFightAIData = null;
            var _loc_4:Point = null;
            var _loc_5:Point = null;
            var _loc_6:Point = null;
            var _loc_2:* = AutoFightBossSelectAI.instance.getEntity() as MonsterPlayer;
            if (_loc_2 == null)
            {
                return false;
            }
            if (_loc_2 == this.getCurFightingTarget())
            {
                return true;
            }
            ThingUtil.selectEntity = _loc_2;
            _loc_3 = AIFactory.instance.outFollowFightAIData();
            _loc_3.skillInfo = param1;
            FightUtil.selectEntityBySkill(_loc_3, Cache.instance.shortcut.isLastKeyByClick);
            if (_loc_3.target == null)
            {
                ThingUtil.selectEntity = null;
            }
            if (_loc_3.target == null && _loc_3.point == null)
            {
                AIFactory.instance.inFollowFightAIData(_loc_3);
                return false;
            }
            if (!SkillUtil.canMapUseSkill(param1, _loc_3))
            {
                return false;
            }
            if (_loc_3.isSkillThenWalk)
            {
                if (!PetBreakCopyUtil.player.entityInfo.fighting)
                {
                    return false;
                }
                this.cancelAll();
                _loc_4 = new Point(_loc_3.point.x, _loc_3.point.y);
                _loc_5 = GeomUtil.getPointByDistance(PetBreakCopyUtil.player.x2d, PetBreakCopyUtil.player.y2d, _loc_3.point.x, _loc_3.point.y, _loc_3.range - 20);
                _loc_3.point.x = _loc_5.x;
                _loc_3.point.y = _loc_5.y;
                this.addFightOnce(_loc_3);
                this.addCallback(SkillController.skillThenWalkCallback, [_loc_4, 50]);
                this.startAIList();
                return true;
            }
            else if (_loc_3.target != null)
            {
                if (_loc_3.target is MonsterPlayer && BossRule.isCollectBoss(_loc_3.target as MonsterPlayer))
                {
                    _loc_2 = _loc_3.target as MonsterPlayer;
                    if (_loc_2.entityID == Cache.instance.skill.waittingServerCollectID || !BossRule.isBossTypeCanSelect((_loc_3.target as MonsterPlayer).bossInfo.type))
                    {
                        AIFactory.instance.inFollowFightAIData(_loc_3);
                        return false;
                    }
                    this.cancelAll();
                    this.addMoveTo(new Point(_loc_2.x2d, _loc_2.y2d), _loc_2.entityInfo.bodySize + RolePlayer.instance.entityInfo.bodySize);
                    this.addCollectAI(_loc_2);
                    this.startAIList();
                    return true;
                }
                else
                {
                    this.cancelAll();
                    if (GeomUtil.calcDistance(RolePlayer.instance.x2d, RolePlayer.instance.y2d, _loc_2.x2d, _loc_2.y2d) >= 500)
                    {
                        this.addMoveTo(new Point(_loc_2.x2d, _loc_2.y2d), _loc_3.range + 100);
                    }
                    this.addFollowFight(_loc_3);
                    this.startAIList();
                    return true;
                }
            }
            else if (_loc_3.point != null)
            {
                if (!PetBreakCopyUtil.player.entityInfo.fighting)
                {
                    return false;
                }
                this.cancelAll();
                _loc_6 = new Point(_loc_3.point.x, _loc_3.point.y);
                this.addMoveTo(_loc_6, _loc_3.range);
                this.addFollowFight(_loc_3);
                this.startAIList();
                return true;
            }
            return false;
        }// end function

        public function addCollectAI(param1:MonsterPlayer) : void
        {
            var _loc_2:* = new CollectAI();
            var _loc_3:* = AIFactory.instance.outAIData();
            _loc_3.target = param1;
            _loc_2.data = _loc_3;
            this._aiList.push(_loc_2);
            return;
        }// end function

        public function addFollowFight(param1:FollowFightAIData) : void
        {
            var _loc_2:IAICommand = null;
            if (param1.skillInfo == null)
            {
                param1.skillInfo = Cache.instance.skill.getFirstSkill();
                if (param1.skillInfo == null)
                {
                    return;
                }
            }
            _loc_2 = new FollowFightAI();
            _loc_2.data = param1;
            this._aiList.push(_loc_2);
            return;
        }// end function

        public function addMoveTo(param1:Point, param2:int = -1, param3:Boolean = false) : void
        {
            var _loc_6:AstarTurnPoint = null;
            var _loc_7:Array = null;
            var _loc_8:int = 0;
            var _loc_9:Object = null;
            var _loc_10:int = 0;
            var _loc_4:* = new Point(PetBreakCopyUtil.player.x2d, PetBreakCopyUtil.player.y2d);
            var _loc_5:* = Scene3DClickProcessor.findPath(_loc_4.x, _loc_4.y, param1.x, param1.y, true);
            if (_loc_5.length > 0)
            {
                _loc_8 = 0;
                while (_loc_8 < _loc_5.length)
                {
                    
                    _loc_9 = _loc_5[_loc_8];
                    if (_loc_9 is AstarTurnPoint)
                    {
                        _loc_6 = _loc_9 as AstarTurnPoint;
                        this.addJump(new Point(_loc_6._x + 0.5, _loc_6._y + 0.5), param3);
                    }
                    else
                    {
                        _loc_10 = 0;
                        if (_loc_8 == (_loc_5.length - 1))
                        {
                            _loc_10 = param2;
                        }
                        this.addMoveByPath(_loc_9 as Array, _loc_10, param3);
                    }
                    _loc_8++;
                }
            }
            return;
        }// end function

        public function addMoveByPath(param1:Array, param2:int = -1, param3:Boolean = false) : void
        {
            var _loc_4:* = new MoveByPathAI();
            var _loc_5:* = AIFactory.instance.outAIData();
            _loc_4.data = _loc_5;
            _loc_5.params = param1;
            if (param2 != -1)
            {
                MoveByPathAI(_loc_4).range = param2;
            }
            if (param3)
            {
                this._aiList.unshift(_loc_4);
            }
            else
            {
                this._aiList.push(_loc_4);
            }
            return;
        }// end function

        public function addJump(param1:Point, param2:Boolean = false) : void
        {
            var _loc_3:* = new JumpAI();
            var _loc_4:* = AIFactory.instance.outAIData();
            _loc_3.data = _loc_4;
            _loc_4.target = param1;
            if (param2)
            {
                this._aiList.unshift(_loc_3);
            }
            else
            {
                this._aiList.push(_loc_3);
            }
            return;
        }// end function

        public function addFightOnce(param1:FollowFightAIData) : void
        {
            var _loc_2:* = new FightOnceAI();
            _loc_2.data = param1;
            this._aiList.push(_loc_2);
            return;
        }// end function

        public function addDelayAI(param1:int) : void
        {
            var _loc_2:IAICommand = null;
            var _loc_3:AIData = null;
            _loc_2 = new DelayAI();
            _loc_3 = AIFactory.instance.outAIData();
            _loc_2.data = _loc_3;
            _loc_3.params = param1;
            this._aiList.push(_loc_2);
            return;
        }// end function

        public function addCallback(param1:Function, param2:Object = null) : void
        {
            var _loc_3:* = new CallBackData();
            _loc_3.meRole = PetBreakCopyUtil.player;
            _loc_3.scene = Game.scene;
            var _loc_4:* = new CallBackAI();
            _loc_4.data = _loc_3;
            _loc_3.callback = param1;
            _loc_3.params = param2;
            this._aiList.push(_loc_4);
            return;
        }// end function

        public function addPassToMap(param1:SPassPoint) : void
        {
            var _loc_2:IAICommand = null;
            var _loc_3:AIData = null;
            _loc_2 = new PassAI();
            _loc_3 = AIFactory.instance.outAIData();
            _loc_2.data = _loc_3;
            _loc_3.params = param1;
            this._aiList.push(_loc_2);
            return;
        }// end function

        public static function get instance() : AutoFightAI
        {
            if (_instance == null)
            {
                _instance = new AutoFightAI;
            }
            return _instance;
        }// end function

    }
}
